<template>
  <div class="virtual-currency-log">
    <div v-if="virtualLog.length>0">
      <van-list v-model="loading"
                :finished="finished"
                :error.sync="error"
                error-text="请求失败，点击重新加载"
                finished-text=""
                @load="onLoad">
        <div class="virtual-log-item"
             v-for="(row,index) in virtualLog"
             :key="index">
          <h3>{{row.title}}</h3>
          <p class="time">{{row.create_time}}</p>
          <span class="num"
                v-if="row.is_add==1">+{{row.change_num}}</span>
          <span class="num"
                v-else>-{{row.change_num}}</span>
        </div>
      </van-list>
    </div>
    <div v-else>
      <no-data :noData=noData></no-data>
    </div>

  </div>
</template>

<script>
import { getVirtualCurrencyInfo } from '@/api/user/member/memberApi'
import noData from '@/components/noData/index'
// import noDataImg from '@img/user/no-data.png'
import Vue from 'vue'
export default Vue.extend({
  name: 'index',
  components: {
    noData
  },
  data() {
    return {
      noData: {
        img: 'https://img.wifenxiao.com/h5-wfx/images/user/no-data.png',
        width: '214px',
        text: '暂无数据',
        txtMarginTop: '-30px'
      },
      virtualLog: [],
      loading: false,
      finished: false,
      error: false,
      p: 2
    }
  },
  methods: {
    init() {
      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 10000)

      getVirtualCurrencyInfo().then(res => {
        this.$loadingWrap.close()
        if (res.status == 1) {
          this.virtualLog = res.data.list
        } else {
          this.$Error(res.msg)
        }
      })
    },
    onLoad() {
      this.loading = true
      const data = {
        p: this.p
      }
      getVirtualCurrencyInfo(data)
        .then(res => {
          this.loading = false
          if (res.data.list.length > 0) {
            this.virtualLog.push(...res.data.list)
            this.p++
          } else {
            this.finished = true
          }
        })
        .catch(() => {
          this.error = true
        })
    }
  },
  created() {
    this.init()
  }
})
</script>

<style lang="scss">
@import "../../../../../../styles/mixin";
.virtual-currency-log {
  margin: 20px 30px;
  .virtual-log-item {
    position: relative;
    padding: 34px 100px 34px 0;
    border-bottom: 1px solid #ededed;
    h3 {
      line-height: 1.2;
      font-size: 28px;
    }
    .time {
      margin-top: 16px;
      font-size: 24px;
      color: #999;
    }
    .num {
      position: absolute;
      right: 4px;
      top: 50%;
      transform: translateY(-50%);
      font-size: 32px;
      color: #fd2049;
      font-weight: bold;
    }
  }
}
</style>